import request from "@/utils/request";
import { IResponse, IStep } from "./type";
import { ServiceKey } from "@/utils/constant";

export enum PathPlanUrl {
  DrivingCar = "driving",
}

interface IDrivingCarResponse {
  destination: string;
  origin: string;
  paths: Array<{
    // 距离：米
    distance: number;
    // 时间：秒
    duration: number;
    // 步骤
    steps: IStep[];
  }>;
}
/**
 * 汽车路径规划
 * @param origin 出发点 经度在前，纬度在后，经度和纬度用","分割
 * @param destination 目的地 经度在前，纬度在后，经度和纬度用","分割
 * @returns {IDrivingCarResponse} 路径规划信息
 */
export const drivingCar = (origin: string, destination: string) => {
  return request.get<PathPlanUrl, IResponse<IDrivingCarResponse>>(
    PathPlanUrl.DrivingCar,
    { params: { origin, destination, key: ServiceKey } }
  );
};
